﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EasyLib.Test
{
    public static class ExceptionAssert
    {
        public static void AreThow(Action action)
        {
            bool _thow;
            try
            {
                action();
                _thow = false;
            }
            catch
            {
                _thow = true;
            }

            Assert.IsTrue(_thow, "没有抛出异常");
        }

        public static void AreThow(Action action, Type exceptionType)
        {
            bool _thow;
            try
            {
                action();
                _thow = false;
            }
            catch (Exception exp)
            {
                _thow = exp.GetType() == exceptionType;
            }

            Assert.IsTrue(_thow, string.Format("没有抛出 {0} 异常", exceptionType.FullName));
        }
    }
}
